package com.fary.net;

public abstract class SocketWrapperBase<E> {

    private final E socket;
    private final AbstractEndpoint<E> endpoint;
    protected volatile SocketBufferHandler socketBufferHandler = null;

    private volatile long readTimeout = -1;
    private volatile long writeTimeout = -1;

    private volatile int keepAliveLeft = 100;

    public SocketWrapperBase(E socket, AbstractEndpoint<E> endpoint) {
        this.socket = socket;
        this.endpoint = endpoint;
    }

    public AbstractEndpoint<E> getEndpoint() {
        return endpoint;
    }

    public E getSocket() {
        return socket;
    }

    public void setReadTimeout(long readTimeout) {
        if (readTimeout > 0) {
            this.readTimeout = readTimeout;
        } else {
            this.readTimeout = -1;
        }
    }

    public void setWriteTimeout(long writeTimeout) {
        if (writeTimeout > 0) {
            this.writeTimeout = writeTimeout;
        } else {
            this.writeTimeout = -1;
        }
    }

    public void setKeepAliveLeft(int keepAliveLeft) {
        this.keepAliveLeft = keepAliveLeft;
    }


    public abstract boolean isClosed();

}